package gui.Machine;

import gui.JTable_ColumnData;
import gui.JTable_StockData;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;

import model.Machine;

/**
 * No Need to change this class.
 * 
 * @author Csaba Tarkanyi
 */
public class MJTable_StockTableData extends AbstractTableModel {
	static final public JTable_ColumnData m_columns[] = {
			new JTable_ColumnData("ID", 60, JLabel.LEFT),
			new JTable_ColumnData("Name", 160, JLabel.LEFT),
			new JTable_ColumnData("Machine Type", 160, JLabel.LEFT) };
	protected List<JTable_StockData> m_list;
	protected Date m_date;

	public MJTable_StockTableData() {
		m_list = new ArrayList<JTable_StockData>();
	}

	/**
	 * TODO
	 * 
	 * @param Machine
	 */
	public void setDefaultData(List<Machine> machine) {
		m_list.clear();

		for (Machine m : machine) {
			m_list.add(new JTable_StockData(m.getID(), m.getName(), m
					.getMachineType().getName()));
		}
	}

	public int getRowCount() {
		return m_list == null ? 0 : m_list.size();
	}

	public int getColumnCount() {
		return m_columns.length;
	}

	public String getColumnName(int column) {
		return m_columns[column].m_title;
	}

	public boolean isCellEditable(int nRow, int nCol) {
		return false;
	}

	public Object getValueAt(int nRow, int nCol) {
		if (nRow < 0 || nRow >= getRowCount())
			return "";
		JTable_StockData row = (JTable_StockData) m_list.get(nRow);
		switch (nCol) {
		case 0:
			return row.getM_ID();
		case 1:
			return row.getM_Name();
		case 2:
			return row.getM_MachineType();
		}
		return "";
	}
}